package com.ios.model.entity;

import com.ios.mapper.ReservationMapper;
import com.ios.model.enums.ReservationStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 预约状态定时任务
 */
@Component
public class ReservationStatusTask {

    @Autowired
    private ReservationMapper reservationMapper;

    /**
     * 每天凌晨检查预约状态
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void updateReservationStatus() {
        // 将过期的待签到状态更新为未签到
        reservationMapper.updateExpiredReservations(
                ReservationStatus.PENDING_CHECK_IN.getCode(),
                ReservationStatus.NOT_CHECKED_IN.getCode()
        );

        // 将当天开始的预约更新为待签到状态
        reservationMapper.updateTodayReservationsToPendingCheckIn(
                ReservationStatus.PENDING_REVIEW.getCode(),
                ReservationStatus.PENDING_CHECK_IN.getCode()
        );
    }

    /**
     * 每小时检查当前时间段是否开始
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void checkCurrentTimeSlot() {
        // 可以根据具体业务需求实现
        // 例如: 检查当前时间是否进入某个时间段,更新相应预约状态
    }
}